<?php
class MyNumber{
	//this is my own number base (maybe someone else did it but I don't know)
	//it's a base 62 (a-z, A-Z, 0-9).. good to shorten number writing
	var $value, $dec; //string
	const base = 62;
	function __construct($dec){
		//creates MyNumber from decimal
		$this->dec = $dec;
		$this->value = "";
		do{
			$index = ($dec % MyNumber::base);
			$this->value .= MyNumber::getNum($index);
			$dec = floor($dec/MyNumber::base);
		}while($dec > 0);
		$this->value = strrev($this->value);
	}
	function __toString(){
		return $this->value;
	}
	public function getVal(){
		return $this->value;
	}
	public static function getNum($i){ //for 0 to 61 only
		if($i<=25){ 		//a to z
			return chr($i+97);
		}else if($i<=51){	// A to Z
			return chr($i+39);
		}else{				//0 to 9
			return $i-52;
		}
	}
	public static function getDec($ch){ //for MyNumber(0) to MyNumber(61) only
		$asci = ord($ch);
		if($asci>=97 && $asci<=122){	//a to z
			return $asci-97;
		}else if($asci>=65 && $asci<=90){//A to Z
			return $asci-39;
		}else{	//number
			return $asci+4;
		}
	}
	public static function toDec($myNum){
		//convert back to decimal
		$myNum = strrev($myNum);
		$res = 0;
		for($i=0;$i<strlen($myNum);$i++){
			$res += MyNumber::getDec($myNum[$i])*pow(MyNumber::base,$i);
		}
		return $res;
	}
}
?>